
// #ifndef VUE3
import Vue from 'vue'
import App from './App'
//导入store
import store from '@/store/store.js'
//导入网络请求的包
import {$http} from '@escook/request-miniprogram'

//将$http挂载到uni.$http上   uni是根节点，与window，wx相似
uni.$http = $http
//设置请求的根路径
// $http.baseUrl = 'https://www.showdoc.com.cn/128719739414963/2612400282844951'
$http.baseUrl = 'https://api-hmugo-web.itheima.net'
//请求拦截器实现loading效果
$http.beforeRequest = function(options){
	uni.showLoading({
		title:'数据加载中...'
	})
	console.log(store)
	//判断当前请求的地址是否有/my/字段，是否需要权限访问
	if(options.url.indexOf('/my/') !== -1){
		options.header = {
			//向头文件添加一个自定义字段存储token值
			Authorization:store.state.m_address.token
		}
	}
}
//响应拦截器
$http.afterRequest = function(){
	//关闭loading
	uni.hideLoading()
}

//封装请求失败的弹框
uni.$showMsg = function(title = '数据请求失败',duration = 1500) {
	uni.showToast({
		title,
		duration,
		icon:'none'
	})
}

Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
    ...App,
	//将store挂载到Vue实例上
	store
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
import App from './App.vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif